<template>
	<view class="taskAllocation_wrapper" :style="{paddingBottom: (bottom+44)+'px'}">
		<u-navbar title='装修进度' :autoBack="true" leftIconColor="#1E272E" bgColor="transparent" :titleStyle="{fontWeight:700,fontSize:'32rpx',color:'#1E272E'}" ></u-navbar>
		<image
			src="https://renovationcdn.jiachuangnet.com/details1/bg.png"
			class='bg' style="height: 476rpx;width: 100%;"></image>
		<view class="container">
			<view class="taskAllocation_msg">
				<view class="flex case_wrappper" style="justify-content: start">
					<view class="case_item">
						<view class="flagship" v-if="info.status==1">
							进行中
						</view>
						<view class="flagship" v-if="info.status==3">
							已完成
						</view>
						<view class="flagship" v-if="info.status==2">
							已逾期
						</view>
						<image :src="info.storeImg.includes('http')?info.storeImg:'https://'+info.storeImg" mode="" class="case_img" v-if="info.storeImg"></image>
						<image src="https://renovationcdn.jiachuangnet.com/details1/noPic.png" mode="" class="case_img" v-else></image>
					</view>
					<view class="taskMsg">
						<view class="flex">
							<view class="taskTital"  v-if="info.assignName">
								{{info.assignName}}
							</view>
							<view class="tag">
								<image src="https://renovationcdn.jiachuangnet.com/details1/zhuangxiu.png" mode="" style="width: 34rpx;height: 34rpx;padding-right: 19rpx;"></image>
								装修
							</view>
						</view>
						<view class="timer"  v-if="info.createTime">
							发布时间： {{info.createTime.split(' ')[0]}}
						</view>
						<view style="position: relative;" v-if="info.percent">
							<u-line-progress  :percentage="info.percent.split('%')[0]||0" activeColor="#13989A"></u-line-progress>
							<!-- <view class="cicle" v-if="Number(info.percent.split('%')[0])<80"></view> -->
						</view>
						<view class="allocation"   v-if="info.percent">
							已完成{{info.percent}}
						</view>
					</view>
				</view>
				<view class="taskForm">
					<view class="flex alignItem bewteen">
						<view class="label" style="width:200rpx">实际开工日期</view>
						<view class="val" v-if="info.startTime">
							{{info.startTime.split(' ')[0].replace(/-/g, '.')}}
						</view>
					</view>
					<view class="flex alignItem bewteen">
						<view class="label" style="width:auto">地址</view>
						<view class="val" v-if="info.address">
							{{info.address}}
						</view>
					</view>
					<view class="flex alignItem bewteen">
						<view class="label" style="width:200rpx">预计完工日期</view>
						<view class="val" v-if="info.endTime">
							{{info.endTime.split(' ')[0].replace(/-/g, '.')}}
						</view>
					</view>
					<view class="flex alignItem bewteen">
						<view class="label" style="width:auto">工期(天)</view>
						<view class="val" v-if="info.allCount">
							{{info.allCount}}
						</view>
					</view>
					<view class="flex alignItem bewteen">
						<view class="label" style="width:auto">负责人</view>
						<view class="val" v-if="info.managerPhone">
							{{info.managerName}}
						</view>
					</view>
					<view class="flex alignItem bewteen">
						<view class="label" style="width:auto">联系方式</view>
						<view class="val" @click="call" v-if="info.managerPhone">
							{{info.managerPhone}}
							<image src="https://renovationcdn.jiachuangnet.com/details1/phone.png" mode="" style="width: 34rpx;height: 34rpx;margin-left: 22rpx;"></image>
						</view>
					</view>
				</view>
				<view class="titleList">
					<view class="titleList_item">
						<view class="look_box flex" style="border-bottom: 2rpx solid #E2E2E2;">
							<view class="text">
								CAD图
							</view>
							<view class="flex" style="align-items: center;">
								<image src="https://renovationcdn.jiachuangnet.com/details1/look.png" mode="" style="width: 27rpx;height: 20rpx;margin-left: 22rpx;"></image>
								<text  style="margin-left: 10rpx;font-weight: 500;font-size: 30rpx;color: #1E272E;" @click="viewImage">查看</text>
							</view>
						</view>
						<view class="look_box flex">
							<view class="text">
								材料清单
							</view>
							<view class="flex" style="align-items: center;">
								<image src="https://renovationcdn.jiachuangnet.com/details1/look.png" mode="" style="width: 27rpx;height: 20rpx;margin-left: 22rpx;"></image>
								<text  @click='toPath("replenishmentRecord")' style="margin-left: 10rpx;font-weight: 500;font-size: 30rpx;color: #1E272E;">查看</text>
							</view>
						</view>
					</view>
					
					<view class="titleList_item_1" style="height: auto;">
						<view class="text" >
							任务详情
						</view>
						<view class="taskList_wrapper">
							  <u-tabs :list="taskStateList" :current="currentTask" @click="changeTaskState" :activeStyle="{ color: '#1E272E' } " :inactiveStyle="{ color: '#868686' } " lineColor="#13989A"></u-tabs>
								<view class="taskList_wrapper" style="margin-top: 25rpx;">
									<view class="taskList_wrapper_item" v-for="(item,index) in info.list" :key="index">
										<view class="day">
											<img src="https://renovationcdn.jiachuangnet.com/details1/day.png" alt="" v-if="item.complete==2" style="width: 34rpx;height: 36rpx;margin-right: 18rpx;"/>
											<img src="https://renovationcdn.jiachuangnet.com/details1/day2.png" alt="" v-else style="width: 34rpx;height: 36rpx;margin-right: 18rpx;"/>
											{{item.assignTaskList.name}}
											<text style="margin-left: 38rpx;font-weight: 500;" v-if="item.todayTime">{{item.todayTime.split(' ')[0].replace(/-/g, '.')}}</text>
											<view class="arrangementBtn1" v-if="item.complete==4" @click="reviewAcceptance(item.id,item.complete)" style="margin-left: 20rpx;" >查看</view>
											<view class="arrangementBtn1" v-if="item.complete==3" @click="reviewAcceptance(item.id,item.complete)" style="margin-left: 20rpx;" >验收</view>
										</view>
										<view class="content-wrapper">
											<view :class="[i==item.assignTaskList.task.length-1?'content_end':' ','content']" v-for="(v,i) in item.assignTaskList.task" :key="i" >
												<view class="flex" style="align-items: center;">
													<view class="solit"></view>
													<view style="margin-right: 18rpx;">
														{{v.taskName}}
													</view>
													<view class="tag_wrapper"  v-if="item.complete==2">
														<view v-for="(tag,j) in taskAssignmentList[index].taskList" :key="j">
															<view class="tag_item" v-if="tag.taskId==v.taskId">
																<u-tag :text="tag.userName"  size="mini"   bgColor="#fde7ef" color="#ED115E" borderColor="#fde7ef"></u-tag>
															</view>
														</view>
													</view>
													<view class="tag_wrapper" v-else>
														<view v-for="(tag,j) in taskAssignmentList[index].taskList" class="" :key="j">
															<view class="tag_item" v-if="tag.taskId==v.taskId">
																<u-tag :text="tag.userName"  size="mini"   bgColor="#e7f4f5" color="#13989A" borderColor="#e7f4f5"></u-tag>
															</view>
														</view>
													</view>
												</view>
												<!-- <view class="arrangementBtn" v-if="item.complete==0||item.complete==2||(item.complete==1&&v.taskProgressDetailUserName.length==0)" @click="changeUser(v.taskId,item.id)">
													分配师傅
												</view> -->
												<view class="arrangementBtn"  @click="uploadTask(i)">
													上传图片
												</view>
											</view>
										</view>
										
										<view class="tag" v-if="item.complete==0">
											未开始
										</view>
										<view class="tag" v-if="item.complete==1">
											进行中
										</view>
										<view class="tag" v-if="item.complete==2">
											已逾期
										</view>
										<view class="tag" v-if="item.complete==3">
											待验收
										</view>
										<view class="tag" v-if="item.complete==4">
											已完成
										</view>
										<img v-if="item.complete==2" src="https://renovationcdn.jiachuangnet.com/details1/yuqi.png" alt="" style="position: absolute; width: 116rpx;height: 100rpx;top: 14rpx;right: 159rpx;"/>
									</view>
								</view>
						</view>
					</view>
				</view>
				
			</view>
		</view>
		
		
		
	</view>
</template>

<script>

	let app = getApp();
	export default {
		data() {
			return {
				showUploadImage:false,
				bottom: app.globalData.safeBottom,
				currentTask:0,
				info:{},
				assignTaskId:0,
				taskAssignmentList:[],
				loginType:null,
				taskStateList:null,
				isCheck:false
			}
		},
		onShow() {
			this.getTaskProgressVo()
			
		},
		onLoad(option) {
			this.assignTaskId = option.assignTaskId;
			this.loginType= uni.getStorageSync('loginType')
		},
		methods:{
			uploadTask(i){
				
			},
			toPath(url) {
				uni.redirectTo({
					url: `/pages/${url}/index?assignTaskId=${this.assignTaskId}&storeType=${this.info.storeType}&address=${this.info.address}&assignName=${this.info.assignName}`
				})
			},
			viewImage(){
				if(!this.info.cadUrl){
					return uni.$u.toast('暂未上传 :)');
				}
				uni.previewImage({
					current: 0,
					urls: ['http://'+this.info.cadUrl],
					longPressActions: {
						itemList: ['保存图片'],
						success: data=> {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
							uni.closePreviewImage()
							/* 保存图片到系统相册 */
							if(data.tapIndex==0){
								uni.getImageInfo({
											src:'http://'+url,
											success: function(res) {
												console.log(res)
												uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
													filePath:res.path, //图片文件路径
													success: function() {
														uni.showToast({
															title: '图片保存成功',
															icon: 'none',
														});
													},
													fail: function(e) {
														console.log(e);
														uni.showToast({
															title: '图片保存失败',
															icon: 'none',
														});
													},
												});
											},
											fail: function(e) {
												console.log(e);
												uni.closePreviewImage()
												uni.showToast({
													title: '图片保存失败',
													icon: 'none',
												});
											},
										})
							}
						},
													fail: function(err) {
														console.log(err.errMsg);
													}
												}
				});
			},
			reviewAcceptance(assignTaskDetailsId,complete){
				uni.navigateTo({
					url:`/pages/acceptance/index?assignTaskDetailsId=${assignTaskDetailsId}&assignTaskId=${this.assignTaskId}&complete=${complete}`
				})
			},
			call() {
				uni.makePhoneCall({
					phoneNumber: this.info.managerPhone,
					success: (res) => {
						console.log(res)
					}
				})
			},
			changeUser(taskId,assignTaskDetailsId){
				let app = getApp();
				// 初始化
				app.globalData.taskAssignmentList=this.taskAssignmentList
				// 保存起来
				// app.globalData.checkboxValue1=this.checkboxValue1
				
				uni.redirectTo({
					url:`/pages/taskAssignment/index?assignTaskDetailsId=${assignTaskDetailsId}&assignTaskId=${this.assignTaskId}&taskId=${taskId}&isSingle=${true}`
				})
			},
			getTaskProgressVo(){
				uni.$u.http.get('/assign/getTaskProgressVo', {
					params:{
						assignTaskId:this.assignTaskId,
					}
				}).then(res=>{
					console.log(res,'获取任务详情信息')
					if(res){
						this.info=res
						
						this.taskStateList=[
					{
						name:'全部',
						badge: {
							value: res.allCount,
						}
					},{
						name:'待开始',
						badge: {
							value: res.pendingStartCount,
						}
					},{
						name:'进行中',
						badge: {
							value: res.inProgressCount,
						}
					},{
						name:'待验收',
						badge: {
							value: res.pendingCount,
						}
					},{
						name:'已逾期',
						badge: {
							value: res.overdueCount,
						}
					},{
						name:'已完成',
						badge: {
							value: res.completedCount,
						}
					},]
					
					
					
						this.taskAssignmentList=res.list.map(item=>{
							let arrList=[]
							item.assignTaskList.task.forEach(v=>{
								v.taskProgressDetailUserName.forEach(user=>{
									arrList.push({
										userName:user.userName,
										completeUserId:user.userId,
										taskId:v.taskId
									})
									
								})
								
							})
							return {
								assignTaskId:this.assignTaskId,
								assignTaskDetailsId:item.id,
								taskList:arrList
							}
						})
						
					}
					
				})
			},
			changeTaskState(e){
				console.log(e)
				//  0 未开始 1 进行中 2 已逾期 3 待验收 4 已完成
				let complete=null
				if(e.name=='待开始'){
					complete=0
				}else if(e.name=='进行中'){
					complete=1
				}else if(e.name=='已逾期'){
					complete=2
				}else if(e.name=='待验收'){
					complete=3
				}else if(e.name=='已完成'){
					complete=4
				}
				
				uni.$u.http.get('/assign/getTaskProgressVo', {
					params:{
						assignTaskId:this.assignTaskId,
						complete,
					}
				}).then(res=>{
					if(res){
						this.info=res
						this.taskAssignmentList=res.list.map(item=>{
							let arrList=[]
							item.assignTaskList.task.forEach(v=>{
								v.taskProgressDetailUserName.forEach(user=>{
									arrList.push({
										userName:user.userName,
										completeUserId:user.userId,
										taskId:v.taskId
									})
									
								})
								
							})
							return {
								assignTaskId:this.assignTaskId,
								assignTaskDetailsId:item.id,
								taskList:arrList
							}
						})
					}
					
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bg {
		width: 750rpx;
		height: 430rpx;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 1;
	}
	.container {
		width: 700rpx;
		position: absolute;
		top: 180rpx;
		left: 25rpx;
		z-index: 2;
		// min-height: 100vh;
		padding-bottom: 200rpx;
	}
	
	.taskForm{
		background: #FFFFFF;
		border-radius: 20rpx;
		font-size: 30rpx;
		padding: 23rpx;
		.alignItem{
			 line-height: 62rpx;
			  color: #868686;
			  .val{
				  text-align: right;
				  font-weight: 500;
				  font-size: 30rpx;
				  color: #1E272E;
			  }
		}
	}
	
	.arrangementBtn1{
		color: #32b4c3;
		background-color: #e7f4f5;
		padding: 5rpx 10rpx;
		border-radius: 30rpx;
		white-space: nowrap;
		box-sizing: border-box;
		font-weight: 500;
		font-size: 26rpx;
	}
	
	.bottom {
		position: fixed;
		bottom: 0;
		left: 0;
		background-color: white;
		z-index: 10000;
		width: 100%;
		padding: 20rpx 0;
		min-height: 20rpx;
	}
	.titleList{
		.titleList_item_1{
			margin-top: 21rpx;
			.text{
				font-weight: bold;
				font-size: 32rpx;
				color: #1E272E;
				line-height: 40rpx;
			}
			.taskList_wrapper{
				.stateTag{
					position: absolute;
					top: 0;
					right: 0;
					line-height: 44rpx;
					padding: 0px 15rpx;
					border-radius: 12rpx;
					background-image: linear-gradient(90deg, #3dd4a7 0%, #00ffff 100%, #00ffff 100%);
					color: #ffffff;
					text-align: center;
				}
				.taskList_wrapper_item{
					background: #FFFFFF;
					border-radius: 20rpx;
					padding: 23rpx;
					position: relative;
					margin-bottom: 22rpx;
					font-weight: 500;
					font-size: 30rpx;
					color: #1E272E;
					.day,.time{
						display: flex;
						font-size: 30rpx;
						font-weight: bold;
						height: 92rpx;
						align-items: center;
						border-bottom: 2px dashed #e0f1f2;
						
					}
					.tag_wrapper{
						justify-content: start;
						max-width: 260rpx;
						display: flex;
						flex-wrap: wrap;
						.tag_item{
							margin: 1rpx;
						}
					}
					.tag{
						width: 110rpx;
						background: #13989A;
						border-radius: 0 20rpx 0 20rpx;
						position: absolute;
						line-height: 44rpx;
						box-sizing: border-box;
						color: #ffffff;
						text-align: center;
						top: 0;
						right: 0;
						font-size: 22rpx;
					}
					.content_end{
						border-bottom:unset !important;
					}
					::v-deep.content{
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 30rpx 0rpx;
						border-bottom: 1px solid #E2E2E2;
						.arrangementBtn{
							color: #32b4c3;
							background-color: #e7f4f5;
							padding: 10rpx 20rpx;
							border-radius: 30rpx;
							white-space: nowrap;
							box-sizing: border-box;
						}
						.u-tag-wrapper{
							margin: 0 5rpx;
						}
						.solit{
							width: 15rpx;
							height: 15rpx;
							background: #D2D2D2;
							border-radius: 50%;
							margin-right: 20rpx;
						}
					}
				}
			}
		}
		.titleList_item{
			background: #FFFFFF;
			border-radius: 20rpx;
			font-size: 30rpx;
			padding: 23rpx;
			margin-top: 21rpx;
			.text{
				font-weight: 500;
				font-size: 30rpx;
				color: #1E272E;
			}
			.look_box{
				justify-content: space-between;
				height: 97rpx;
				align-items: center;
			}
			
		}
	
	}
	
	.taskAllocation_wrapper{
		font-size: 24rpx;
		background-color: #f5f5f5;
		.taskAllocation_msg{
		}
	}
	
	.case_wrappper{
		justify-content: space-between;
		margin-bottom: 34rpx;
		.case_item{
			position: relative;
			border-radius: 10rpx;
			overflow: hidden;
			.case_img{
				width: 226rpx;
				height: 261rpx;
				border-radius: 20rpx;
			}
		}
		::v-deep.taskMsg{
			// padding-right: 70rpx;
			.u-line-progress{
				overflow: visible;
			}
			.u-line-progress__text{
				width: 69rpx;
				line-height: 35rpx;
				text-align: center;
				background: #13989A;
				border-radius: 17rpx;
				border: 1px solid #FFFFFF;
				margin: unset;
				margin-right: -40rpx;
			}
		}
		.taskMsg{
			padding-left: 28rpx;
			flex: 1;
			.taskTital{
				 max-width: 220rpx;
				 font-weight: 700;
				 font-size: 36rpx;
				 color: #1E272E;
				 overflow: hidden;
				 text-overflow:ellipsis;
				 white-space: nowrap;
			}
			.cicle{
				width: 26rpx;
				height: 26rpx;
				border-radius: 50%;
				border: 2px solid #13989A;
				box-sizing: border-box;
				position: absolute;
				right: 0;
				top: 0;
				transform: translate(50% -50%);
			}
			.tag{
				width: 146rpx;
				height: 45rpx;
				background: #b3d3d3;
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				font-weight: 500;
				font-size: 28rpx;
				color: #13989A;
				padding-left: 8rpx;
				box-sizing: border-box;
				margin-left: 21rpx;
			}
			.timer{
				font-weight: 500;
				font-size: 28rpx;
				color: #1E272E;
				margin-top: 25rpx;
				margin-bottom: 51rpx;
			}
			.allocation{
				font-weight: 500;
				font-size: 20rpx;
				color: #1E272E;
				margin-top: 12rpx;
			}
		}
		.flagship{
			width: 110rpx;
			line-height: 40rpx;
			background: #13989A;
			font-size: 22rpx;
			color: #FFFFFF;
			border-radius: (20rpx 0 20rpx 0 );
			text-align: center;
			position: absolute;
			top:0;
			left: 0;
			z-index:1;
		}
	}
</style>